<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('scan_logs', function (Blueprint $table) {
            $table->id();
            $table->foreignId('scanner_user_id')->nullable()->constrained('users')->onDelete('set null')->comment('扫码用户ID');
            $table->foreignId('car_owner_id')->constrained()->onDelete('cascade')->comment('被扫码车主ID');
            $table->timestamp('scan_time')->useCurrent()->comment('扫码时间');
            $table->boolean('call_made')->default(false)->comment('是否拨打电话');
            $table->string('ip_address', 50)->nullable()->comment('扫码IP地址');
            $table->string('device_info', 255)->nullable()->comment('设备信息');
            
            $table->index('scanner_user_id');
            $table->index('car_owner_id');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('scan_logs');
    }
};
